package com.example.demo.mapper;

import com.example.demo.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserMapper {
    List<User> selectall();//  查询所有

    ///  直接定义在controller
    @Insert("insert into user (ACCOUNT_ID, NAME, TOKEN, GMT_CREATE, GMT_MODIFIED, AVATAR_URL) values ( #{accountId},#{name},#{token},#{gmtCreate},#{gmtModified},#{avatarUrl} )")
    void insert(User user);

    @Select("select * from user where token = #{token}")
    User findByToken(@Param("token") String token);

    @Select("select * from user where id = #{id}")
    User findById(@Param("id") Integer id);

    @Select("select * from user where ACCOUNT_ID = 3")
    User findByAccountId(String accountId);


    @Update("update  user set name= 2,token=#{token},GMT_MODIFIED= 2,avatar_url= 2 where id= 1")
    void Update(User user);
}
